<template>
  <van-submit-bar :price="cartMsg.cartAmount*100" button-text="提交订单" @submit="onSubmit">
    <van-checkbox v-bind:value="allCheck" @click="allCheckAc" :disabled="isEditClicked"  >全选</van-checkbox
    >
    <template #tip v-if="getCartDBList.length > 0">
      累计共<span>{{cartMsg.cartCount}}</span>件商品，可点击<van-button
        type="default"
        size="small"
        round
        @click="changeEdit"
        >{{ isEditClicked ? "完成编辑" : "编辑" }}</van-button
      >按钮进行商品数量修改
    </template>
  </van-submit-bar>
</template>

<script>
export default {
  name: "Submit",
  props: ["getCartDBList", "allCheckAction"],
  data() {
    return {
      isEditClicked: true,
      allCheck: false,
    };
  },
  mounted() {
      this.$bus.$on("changeAllState",this.changeAllState);
  },
   computed: {
    cartMsg() {
      let cartTotal = {cartCount:0,cartAmount:0};
      this.getCartDBList.forEach(element => {
          cartTotal.cartCount+=element.num
          if(element.checked){
              cartTotal.cartAmount+=element.num*element.price
          }
      });
      return cartTotal;
    },
  },
  beforeDestroy(){
      this.$bus.$off("changeAllState");
  },
  methods: {
    allCheckAc() {
      this.allCheck = !this.allCheck;
      this.allCheckAction(this.allCheck);
    },
    changeAllState(value){
        this.allCheck=value;
    },
    changeEdit(){
        console.log("11");
        this.isEditClicked=!this.isEditClicked
        this.$bus.$emit('isEditChange',this.isEditClicked)
    },
    onSubmit() {
      this.$toast("该地区不支持购买");
    },
  },
};
</script>

<style>
.van-submit-bar {
  margin-bottom: 50px;
}
.van-button--round {
  position: relative;
  top: -2px;
}
</style>